package com.um.jdy.platform.order.controller;


import com.um.jdy.platform.order.entity.vo.OrderOverviewVO;
import com.um.jdy.platform.order.manager.OrderOverviewManager;
import com.um.jdy.platform.screen.entity.vo.ScreenDataVO;
import com.um.springboot.starter.annotation.ApiPermission;
import com.um.springboot.starter.annotation.TokenRequired;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.service.CacheService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.TimeUnit;


/**
 * 充电订单
 *
 * @author cs
 * 日期 2023/6/7
 * 版权所有 广州优匠科技有限公司
 */
@RestController
@RequestMapping("/api/v1/cms/order/overview")
@Api(tags = "订单概览", description = "订单概览")
@ApiPermission("order_overview")
@TokenRequired
@Validated
public class OrderOverviewController extends BaseController<OrderOverviewManager> {

    @Autowired
    RedisTemplate redisTemplate;

    private static final String CACHE_KEY = "orderOverview";

    @ApiPermission("data")
    @ApiOperation("订单概览")
    @GetMapping({"data"})
    public Response<OrderOverviewVO> getOverviewData(){
        OrderOverviewVO data = (OrderOverviewVO)redisTemplate.opsForValue().get(CACHE_KEY+"-"+manager.getComId());
        if (data == null) {
            data = manager.getOverviewData();
            redisTemplate.opsForValue().set(CACHE_KEY+"-"+manager.getComId(), data, 1L, TimeUnit.MINUTES);
        }
        return Response.success(data);
    }

}
